package leecode

import "strings"

func reverseOnlyLetters(s string) string {
	low := 0
	temp := strings.ToUpper(s)
	last := len(s) - 1
	arr := []byte(s)
	tempArr := []byte(temp)
	//a 97
	//A 65
	for low < last {
		if (tempArr[low] >= 'A' && tempArr[low] <= 'Z') && (tempArr[last] >= 'A' && tempArr[last] <= 'Z') {
			arr[low], arr[last] = arr[last], arr[low]
			low++
			last--
		}
		if tempArr[low] < 'A' || tempArr[low] > 'Z' {
			low++
		}
		if tempArr[last] < 'A' || tempArr[last] > 'Z' {
			last--
		}
	}
	return string(arr)
}
